<div class="container-fluid" style="margin-top: 10px;">
    <div class="row">
        <form id="alterForm" method="post" action="addAlter">
            <div class="col-sm-12">
                <label>变动库存</label>
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>库存编号</th>
                        <th>库存分类</th>
                        <th>品牌</th>
                        <th>规格型号</th>
                        <th>单价</th>
                        <th>库存数量</th>
                        <th>损毁报废数量</th>
                        <th>库存价值（总价）</th>
                        <th>供货商</th>
                        <th>取得方式</th>
                        <th>存放地点</th>
                        <th>备注</th>
                    </tr>
                    </thead>
                    <tbody>

                    {volist name='$alterItemList' id='vo'}
                    <tr>
                        <td>{$vo.STOCK_NO}</td>
                        <td>{$vo.TYPE_NAME}</td>
                        <td>{$vo.BRAND}</td>
                        <td>{$vo.SPEC}</td>
                        <td>{$vo.PRICE}</td>
                        <td>{$vo.STOCK_NUM}</td>
                        <td>{$vo.ALTER_NUM}</td>
                        <td>{$vo.TOTAL_PRICE}</td>
                        <td>{$vo.SUPPLIER}</td>
                        <td>{$vo.GET_TYPE}</td>
                        <td>{$vo.PLACE}</td>
                        <td>{$vo.ALTER_REMARK}</td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>

            <div class="col-sm-12">
                <label>变动表单</label>
                <div class="col-sm-12" style="border: 1px solid #ddd;padding: 10px 0px">
                    {:form('text',['title'=>'变动类型','value'=>'报废','disable'=>'disabled'])}
                    {:line()}
                    {:form('text',['title'=>'损毁报废日期','name'=>'ALTER_DATE','value'=>$alterData.ALTER_DATE,'disable'=>'disabled'])}
                    {:form('text',['title'=>'经办人','name'=>'WORK_PERSON','value'=>$alterData.WORK_PERSON,'disable'=>'disabled'])}
                    {:form('text',['title'=>'联系电话','name'=>'PHONE','value'=>$alterData.PHONE,'disable'=>'disabled'])}
                    {:form('text',['title'=>'总价值','name'=>'TOTAL_PRICE','value'=>$alterData.TOTAL_PRICE,'disable'=>'disabled'])}
                    {:form('text',['title'=>'损毁报废原因','name'=>'ALTER_REASON','value'=>$alterData.ALTER_REASON,'disable'=>'disabled','col'=>'col-sm-12'])}
                    {:line()}
                    {:form('text',['title'=>'制单人','disable'=>'disabled','value'=>$alterData.INPUT_NAME])}
                    {:form('text',['title'=>'制单时间','disable'=>'disabled','value'=>$alterData.INPUT_TIME])}

                </div>
            </div>
        </form>
        <!--<div class="col-sm-12" style="margin-top: 10px;text-align: center">-->
            <!--<button id="submit" class="btn btn-info">确认变更</button>-->
        <!--</div>-->
    </div>
</div>

<script>

    $(function () {

        $("[name='ALTER_DATE']").flatpickr();

        $("#submit").on('click',function () {
            layer.confirm('确认执行变更吗？',function (index) {
                layer.close(index);
                layer.load();
                $("#alterForm").ajaxSubmit(function (text) {
                    console.log(text);
                    layer.closeAll('loading');
                    var json = JSON.parse(text);
                    console.log(json);
                    if(json['code']=='200'){
                        layer.alert(json['msg'],{icon:1},function (index) {
                            layer.close(index);
                            parent.location.reload();
                        });
                    }
                    else{
                        layer.alert(json['msg'],{icon:2});
                    }
                });
            });
        });
    });

    function changAlterNum(stockNo) {
        var alterNum = parseInt($("#ALTER_NUM_"+stockNo).val());
        var stockNum = parseInt($("#STOCK_NUM_"+stockNo).val());
        console.log(alterNum);
        console.log(stockNum);
        if (alterNum > stockNum) {
            layer.alert('【损毁报废数量】不能大于【库存数量】',{icon:2});
            return;
        }
        if (isNaN(alterNum)) {
            layer.alert('【损毁报废数量】参数错误',{icon:2});
            return;
        }

        countTotalPrice();
    }

</script>